package com.Hadoop.Writable;

import org.apache.hadoop.io.Writable;

import java.io.*;

public class HadoopWritable {
    public static void main(String[] args) throws IOException {
        StudentHadoop studentHadoop=new StudentHadoop();
        studentHadoop.setId(1L);
        studentHadoop.setName("hadoop");
        FileOutputStream  fileOutputStream=new FileOutputStream("D:\\Hadoop_Writable.txt");
        ObjectOutputStream outputStream=new ObjectOutputStream(fileOutputStream);
        studentHadoop.write(outputStream);
        outputStream.close();
        fileOutputStream.close();

    }

}
class StudentHadoop implements Writable {
    private long id;
    private String name;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeLong(this.id);
        dataOutput.writeUTF(this.name);
    }

    @Override
    public void readFields(DataInput dataInput) throws IOException {
        this.id=dataInput.readLong();
        this.name=dataInput.readUTF();
    }
}
